package com.gongzhiyun.springboot3test.aop;

import com.gongzhiyun.springboot3test.exception.AppException;
import com.gongzhiyun.springboot3test.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;


@Slf4j
@RequiredArgsConstructor
@Component
@Aspect
@Order(10)
public class AuthAop implements BaseAop {
    private final UserService userService;

    @Before("controller()")
    public void before(JoinPoint jp) {
        log.debug("api权限拦截开启==============>{}",userService.checkAuth());
        if (!userService.checkAuth()) {
            throw AppException.getInstance(1000, "需要相关角色登录");
        }
    }



}
